package com.privatbank.servlets;

import com.privatbank.constants.Constants;
import com.privatbank.user.User;
import com.privatbank.userdao.UserDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TestUserListServlet extends HttpServlet {

    private UserDao dao = null;

    @Override
    public void init() {
        dao = new UserDao(Constants.LOGIN, Constants.PASSWORD, Constants.URL);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //List<String> users = new ArrayList<String>();
        List<User> users = null;
        try {
            users = dao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }


        request.setAttribute("users", users);
        //RequestDispatcher dispatch = request.getRequestDispatcher("WEB-INF/userList.jsp");
        RequestDispatcher dispatch = request.getRequestDispatcher("WEB-INF/jsp/userList.jsp");
        dispatch.forward(request, response);
    }

}
